<%--
  Created by IntelliJ IDEA.
  User: 29688
  Date: 2021/3/21
  Time: 18:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8"%>
<html>
<head>
    <title>注册页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../layui-v2.5.7/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../layui-v2.5.7/style/admin.css" media="all">
    <link rel="stylesheet" href="../layui-v2.5.7/style/login.css" media="all">
    <script src="../layui-v2.5.7/layui/layui.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../js/jquery.js"></script>
    <style>
        body {
            background-color: #D9AFD9;
            background-image: linear-gradient(218deg, #D9AFD9 0%, #97D9E1 100%);
            height: 750px;
        }
    </style>
    <script>
        function checkNameExist(){
            $.ajax({
                method:"GET",
                url:"${pageContext.request.contextPath}/checkRegisterName",
                data:{"uname":$("#uname").val()},
                success:function (data) {
                    if(data.toString()==="exist"){
                        $("#registerError").text("用户名已存在")
                    }
                    else{
                        $("#registerError").text("")
                    }
                },
            })
            console.log("ajax获取用户名")
            submitIll()
        }
        function checkPasswordConsist(){
            let val = $("#repass").val();
            let val1 = $("#password").val();
            if(val===val1||val===""||val1===""){
                $("#registerPwdCheck").text("")
            }else{
                $("#registerPwdCheck").text("密码不一致")

            }
            submitIll()
        }
        function submitIll(){
            if($("#registerPwdCheck").text()===""&&$("#registerError").text()===""){
                $("#submit").attr("disabled",false)
            }else {
                $("#submit").attr("disabled",true)
                console.log("注册按钮失效")
            }
        }
    </script>
</head>
<body>


<div class="layadmin-user-login layadmin-user-display-show" id="app" style="display: none;">
    <form class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>校园纸质资料处理系统</h2>
            <p>注册页面</p>
            <p style="color: red" id="registerError"></p>
            <p style="color: red" id="registerPwdCheck"></p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                       for="uname"></label>
                <input type="text" name="uname" id="uname" lay-verify="required" placeholder="用户名"
                       class="layui-input" onblur="checkNameExist()">
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs6">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                               for="LAY-user-login-vercode"></label>
                        <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required"
                               placeholder="图形验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 15px;">
                            <img id="checkCode" style="width: 150px; height: 50px;" src="/code" alt="验证码生成失败"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="password"></label>
                <input type="password" name="password" id="password" lay-verify="pass" placeholder="密码"
                       class="layui-input" onblur="checkPasswordConsist()" >
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="repass"></label>
                <input type="password" name="repass" id="repass" lay-verify="required" placeholder="确认密码"
                       class="layui-input" onblur="checkPasswordConsist()">
            </div>

            <div class="layui-form-item">
                <input class="layui-btn layui-btn-fluid"  type="button"
                       lay-submit lay-filter="LAY-user-reg-submit" value="注册">
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <a href="${pageContext.request.contextPath}/jsp/login.jsp" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>

            </div>
        </div>
    </form>

</div>

<script>
    //加载form模块
    layui.use(['form','layer'], function(){
        let form = layui.form;
        var layer = layui.layer;
        form.on('submit(LAY-user-reg-submit)',function (data){
            $.ajax({
                url:"/register",
                data:data.field,
                type:"post",
                success:function (data){
                    if(data===1){
                        layer.msg("注册成功！");
                    }
                }
            })
        })
    });
    /*获取验证码图片*/
    window.onload = function(){
        /*获取图片对象*/
        let img = document.getElementById("checkCode");
        /*绑定点击事件*/
        img.onclick=function (){
            img.src="/code?"+new Date().getTime();
        }
    }

</script>

</body>
</html>

